#include <bits/stdc++.h>
using namespace std;

#define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

typedef long long LL;

const int N = 25, M = 15;

char s[N][M], t[N][M];

int n, m;

int main(int argc, char const *argv[])
{
	scanf("%d%d", &n, &m);
	for (int i=0; i<n; ++i)
		scanf("%s", s[i]);
	for (int i=0; i<m; ++i)
		scanf("%s", t[i]);
	int q; scanf("%d", &q);
	for (int i=0; i<q; ++i)
	{
		int x; scanf("%d", &x); --x;
		printf("%s%s\n", s[x%n], t[x%m]);
	}
	
	return 0;
}